// pages/index/newcategory/newcategory.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        leftmun: '',//左边菜单
        rightcon: '',//二级菜单
        currentIndex: 0,
        scrolltop: "0"


    },
    Cart: [],
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.id != null) {
            this.categories(options.id);
        } else {
            this.categories(0);
        }
    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    categories: function (id) {
        app.func.getPromise('/categoriesv2')
            .then(([code, res]) => {
                console.log(res);
                if (code == 200) {
                    console.log('1111')
                    this.Cart = res.data;
                    let leftmun = this.Cart.map(v => v.name);
                    let currentIndex = 0;
                    for(let i = 0; i < this.Cart.length;i++) {
                        if(this.Cart[i].id == id) {
                            currentIndex = i;
                        }
                    }
                    let rightcon = this.Cart[currentIndex].subitems;
                    console.log(leftmun, rightcon)
                    this.setData({
                        currentIndex,
                        leftmun,
                        rightcon,
                    })
                }
            });
    },
    changContent(e) {
        const {index} = e.currentTarget.dataset;
        let rightcon = this.Cart[index].subitems;

        this.setData({
            currentIndex: index,
            rightcon: rightcon,
            scrolltop: "0"
        })
    },
    showGery(e) {
        console.log(e)
        let id = e.currentTarget.dataset.id;
        console.log(id)

    }

})